package net.bwie.jtp.dim.trade.function;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.flink.api.common.functions.RichMapFunction;

import java.util.Map;

public class HbaseDimMapFunction extends RichMapFunction<String, String> {
    private final Map<String,String> dimMap;

    public HbaseDimMapFunction(Map<String, String> dimMap) {
        this.dimMap = dimMap;
    }

    @Override
    public String map(String value) throws Exception {
        JSONObject jsonObject = JSON.parseObject(value);
        jsonObject.put("hbase_table_name","dim_"+jsonObject.getString("table_name"));
        jsonObject.put("family_name","info");
        jsonObject.put("row_key_column",dimMap.get(jsonObject.getString("table_name")));

        return jsonObject.toJSONString();
//        {"operate_type":"insert","db_name":"jtp_mall","operate_date":{"taken_count":0,"start_time":"2025-02-10 01:01:01","create_time":"2025-01-11 12:37:05","condition_amount":99.00,"id":1,"range_type":"3301","coupon_name":"口红品类券","coupon_type":"3201","benefit_amount":30.00,"limit_num":100,"operate_time":"2025-01-11 12:37:05"},"hbase_table_name":"dim_coupon_info","table_name":"coupon_info","family_name":"info","ts_ms":1748918812638,"row_key_column":"id"}

    }
    @Override
    public void close() throws Exception {
        super.close();
    }
}
